# -*- coding: utf-8 -*-
"""
模块：贺卡模板的管理、选择与占位符替换
苏以胜负责B部分
"""
def load_templates_internal():
    """模板"""
    return [
        {
            "template_id": "tpl_birthday_01",
            "name": "简约生日祝福",
            "content": "亲爱的[收件人姓名]，\n\n祝你生日快乐，愿你天天开心，岁岁平安！\n\n来自你真诚的朋友，\n[您的署名]\n\n([附加祝福语])",
            "placeholders": ["收件人姓名", "您的署名", "附加祝福语"]
        },
        {
            "template_id": "tpl_festival_01",
            "name": "通用节日祝福",
            "content": "值此[节日名称]佳节之际，\n[收件人姓名]，祝您和您的家人[节日祝福语]！\n\n[您的署名]\n[日期]",
            "placeholders": ["节日名称", "收件人姓名", "节日祝福语", "您的署名", "日期"]
        },
        {
            "template_id": "tpl_thanks_01",
            "name": "感谢卡",
            "content": "尊敬的[收件人姓名]，\n\n衷心感谢您[感谢原因]。\n您的[具体帮助]让我深受感动。\n\n此致\n敬礼！\n[您的署名]\n[日期]",
            "placeholders": ["收件人姓名", "感谢原因", "具体帮助", "您的署名", "日期"]
        }
    ]

def display_templates(templates):
    """显示所有可用模板"""
    print("\n" + "=" * 30)
    print("可用贺卡模板")
    print("=" * 30)
    for idx, template in enumerate(templates, 1):
        print(f"{idx}. {template['name']}")
        print(f"   模板ID: {template['template_id']}")
        print(f"   占位符: {', '.join(template['placeholders'])}")
    print("=" * 30)

def select_template_interaction(templates):
    """
    模板选择交互
    :param templates: 模板列表
    :return: 选择的模板字典或None
    """
    if not templates:
        print("没有可用模板！")
        return None
        
    display_templates(templates)
    
    while True:
        try:
            choice = input("请输入要选择的模板编号(1-{}): ".format(len(templates))).strip()
            idx = int(choice) - 1
            if 0 <= idx < len(templates):
                return templates[idx]
            print("无效的编号，请重新输入！")
        except ValueError:
            print("请输入有效的数字！")